package com.survey.bean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.survey.util.FD;
import com.survey.util.MathExtend;

import tk.mybatis.mapper.annotation.NameStyle;
import tk.mybatis.mapper.code.Style;

@Entity
@Table(name = "t_quesitemlistoption")
@NameStyle(Style.normal)
public class QuesItemListOption {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	private Integer				id;
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "quesItemListId")
	@FD("题目")
	private QuesItemList	quesItemList;
	private Integer				quesItemListId;
	@FD("选项")
	private String				options;
	@FD("选中量")
	@Column(updatable = false)
	private Integer				amount;

	@FD("分值")
	private Integer				score;

	@Transient
	private int						votesize;

	@Transient
	public double getPercent() {
		if (votesize == 0)
			return 0;
		return MathExtend.round(amount * 1.0 / votesize * 100, 1);
	}

	public Integer getScore() {
		return score;
	}

	public void setScore(Integer score) {
		this.score = score;
	}

	public int getVotesize() {
		return votesize;
	}

	public void setVotesize(int votesize) {
		this.votesize = votesize;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public QuesItemList getQuesItemList() {
		return quesItemList;
	}

	public void setQuesItemList(QuesItemList quesItemList) {
		this.quesItemList = quesItemList;
	}

	public Integer getQuesItemListId() {
		return quesItemListId;
	}

	public void setQuesItemListId(Integer quesItemListId) {
		this.quesItemListId = quesItemListId;
	}

	public String getOptions() {
		return options;
	}

	public void setOptions(String options) {
		this.options = options;
	}

	public Integer getAmount() {
		return amount;
	}

	public void setAmount(Integer amount) {
		this.amount = amount;
	}

}
